package com.JZ.QM.service.impl;

import com.JZ.QM.common.dao.EntrustDetailDao;
import com.JZ.QM.common.dao.EntrustRecordDao;
import com.JZ.QM.common.entity.EntrustDetailEntity;
import com.JZ.QM.common.entity.EntrustRecordEntity;
import com.JZ.QM.common.entity.UserCollectEntity;
import com.JZ.QM.common.utils.CommonResult;
import com.JZ.QM.common.utils.PageUtils;
import com.JZ.QM.common.utils.Query;
import com.JZ.QM.service.EntrustRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;

/**
 * @author: cyc
 * @email cyc@gmail.com
 * @date: 2020/7/9 15:08
 */
@Service()
public class EntrustRecordServiceImpl extends ServiceImpl<EntrustRecordDao, EntrustRecordEntity> implements EntrustRecordService {

    @Resource
    EntrustRecordDao entrustRecordDao;
    @Resource
    EntrustDetailDao entrustDetailDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) throws Exception {
        IPage<EntrustRecordEntity> page = this.page(
                new Query<EntrustRecordEntity>().getPage(params),
                new QueryWrapper<EntrustRecordEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 获取委托列表
     * @param tradeId 交易记录id
     * @return
     */
    @Override
    public ArrayList<EntrustDetailEntity> getEntrustRecordsByTradeId(Long tradeId) {
        //条件构造器
        QueryWrapper queryWrapper=new QueryWrapper();
        //委托列表信息
        ArrayList<EntrustDetailEntity> entrustRecordEntities=new ArrayList<>();

        queryWrapper.eq("trade_id",tradeId);

        entrustRecordEntities=entrustDetailDao.getEntrustDetailByTradeId(tradeId);
        return entrustRecordEntities;
    }
}
